package com.hung.trade.goods.api;

import com.hung.trade.common.api.IGoodsApi;
import com.hung.trade.common.constants.TradeEnums;
import com.hung.trade.common.protocol.goods.QueryGoodsReq;
import com.hung.trade.common.protocol.goods.QueryGoodsResp;
import com.hung.trade.common.protocol.goods.ReduceGoodsNumberReq;
import com.hung.trade.common.protocol.goods.ReduceGoodsNumberResp;
import com.hung.trade.goods.service.IGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author hungki
 * @createTime 2018-10-09 下午 4:15
 */
@Controller
public class GoodsApiImpl implements IGoodsApi {
    @Autowired
    private IGoodsService iGoodsService;
    @Override
    @RequestMapping(value = "/queryGoodsById",method = RequestMethod.POST)
    @ResponseBody
    public QueryGoodsResp queryGoodsById(@RequestBody QueryGoodsReq queryGoodsReq) {
        QueryGoodsResp resp =new QueryGoodsResp();
        try {
            resp = iGoodsService.queryGoodsById(queryGoodsReq);
        }catch (Exception e){
            resp.setRetInfo(TradeEnums.RetEnum.FAIL.getDesc()+":"+e.getMessage());
            resp.setRetCode(TradeEnums.RetEnum.FAIL.getCode());
        }
        return resp;

    }

    @Override
    @RequestMapping(value = "/reduceGoodsNumberById",method = RequestMethod.POST)
    @ResponseBody
    public ReduceGoodsNumberResp reduceGoodsNumberById(@RequestBody ReduceGoodsNumberReq reduceGoodsNumberReq) {

        ReduceGoodsNumberResp resp = new ReduceGoodsNumberResp();

        try {
            resp =iGoodsService.reduceGoodsNumber(reduceGoodsNumberReq);
        }catch (Exception e){
            e.printStackTrace();
            resp.setRetInfo(TradeEnums.RetEnum.FAIL.getDesc()+":"+e.getMessage());
            resp.setRetCode(TradeEnums.RetEnum.FAIL.getCode());
        }
        return resp;
    }
}
